$(document).ready(function() {

	$("#name").keydown(function() {
		var e = event || window.event;
		if (e.keyCode == 13) {
			$("#password").focus();
		}

	});

	$("#password").keydown(function(event) {
		var e = event || window.event;
		if (e.keyCode == 13) {
			$("#cpassword").focus();
		}
	});

	$("#cpassword").keydown(function(event) {
		var e = event || window.event;
		if (e.keyCode == 13) {
			$.submit();
		}

	});

	$("#submit").click($.submit);

});

jQuery.submit = function() {
	var _name = $("#name").attr("value");
	var _password = $("#password").attr("value");
	var _cpassword = $("#cpassword").attr("value");
	if (_name == '') {
		$("#returninfo").html("<font color=red>请输入用户名。</font>");
		$("#name").focus();
		return;
	}

	if (_password == '') {
		$("#returninfo").html("<font color=red>密码为空。</font>");
		$("#password").focus();
		return;

	}
	if (_password != _cpassword) {

		$("#returninfo").html("<font color=red>密码不一致请重新输入。</font>");
		$("#cpassword").focus();
		return;
	}

	$.ajax({
		type : "POST",
		url : "./userinfo",
		data : {
			psn_account : _name,
			psn_password : _password
		}
	}).done(function(xml) {
		var info = $(xml).find("result").text();
		if (info == 'success') {
			$("#returninfo").html("<font color=green>创建成功</font>");
		}
		if (info == 'failed') {
			$("#returninfo").html("<font color=red>创建失败</font>");
		}

		if (info == 'duplicated') {
			$("#returninfo").html("<font color=red>用户已经存在</font>");
		}

	});

};
